package com.weixin.paleituo.factory;

import android.support.v4.app.Fragment;

import com.weixin.paleituo.fragment.GoodsHomeFragment;
import com.weixin.paleituo.fragment.HomeFragment;
import com.weixin.paleituo.fragment.MyFragment;
import com.weixin.paleituo.fragment.SharedHouseFragment;
import com.weixin.paleituo.fragment.WuYeFragment;
import com.weixin.paleituo.util.LogUtils;

import java.util.HashMap;

/**
 * Author yichao
 * Time  2017/11/30 9:36
 * Dest  主页fragment的工厂
 */
public class MainFragmentFactory {
    public static String TAG="MainFragmentFactory";
    private static final int HOME_FRAGMENT = 0;
    private static final int GOODS_FRAGMENT = 1;
    private static final int SHARED_HOUSE = 2;
    private static final int WUYE_FRAMENT = 3;
    private static final int MY_FRAGMENT = 4;
    private static HashMap<Integer,Fragment> mMap=new HashMap();

    public static Fragment getFragment(int index) {
        Fragment fragment=null;
        if (mMap.containsKey(index)){
            fragment=   mMap.get(index);
            LogUtils.i(TAG,"复用"+index);
        }else {
            switch (index) {
                case HOME_FRAGMENT:
                    fragment = new HomeFragment();
                    break;
                case GOODS_FRAGMENT:
                    fragment = new GoodsHomeFragment();
                    break;
                case SHARED_HOUSE:
                    fragment = SharedHouseFragment.newInstance();
                    break;
                case WUYE_FRAMENT:
                    fragment = new WuYeFragment();
                    break;
                case MY_FRAGMENT:
                    fragment = new MyFragment();
                    break;

            }
            LogUtils.i(TAG,"新建"+index);
            mMap.put(index,fragment);

        }
        return fragment;

    }


}
